package com.software.cool.service.impl;

import com.software.cool.api.admin.v1.vo.AdminLoginUserVO;
import com.software.cool.common.BaseMapper;
import com.software.cool.entity.TbOrg;
import com.software.cool.mapper.TbOrgMapper;
import com.software.cool.service.ITbOrgService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;

@Service
@Slf4j
public class TbOrgService extends BaseService<TbOrg,String,Object> implements ITbOrgService {

    @Resource
    private TbOrgMapper mapper;
    @Override
    protected BaseMapper<TbOrg> getBaseMapper() {
        return mapper;
    }
    @Value("${file.basedir}")
    private String basedir;


    @Override
    public boolean edit(TbOrg model) {
        boolean result=false;
        try{
            if(model!=null){
                AdminLoginUserVO loginUser=this.getLoginUser(model.getToken());
                model.setUseStatus("normal");
                if(model.getOrgId()==null){
                    model.setCreateTime(new Date());
                    model.setCreateAdminId(loginUser.getUserId());
                    add(model);
                }else{
                    model.setUpdateTime(new Date());
                    model.setUpdateAdminId(loginUser.getUserId());
                    model.setCreateTime(new Date());
                    model.setCreateAdminId(loginUser.getUserId());
                    update(model);
                }
                result=true;
            }
        }catch (Exception e){
            log.error(e.getMessage(),e);
        }
        return result;
    }

    @Override
    public void importData(TbOrg model) throws Exception {
        log.info("importData...");
    }

    @Override
    public void exportData(TbOrg model) throws Exception {
        log.info("exportData...");
    }

    @Override
    public void delOrgByShip(Long shipId) throws Exception {
    }
}
